package com.epfresh.adapter;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.epfresh.R;
import com.epfresh.bean.MerchantEntity;
import com.epfresh.bean.TypeBean;

import multitype.ItemViewBinder;

/**
 * Author: Chen
 * Date: 2019/1/30
 * Desc:
 */
public class SingleAreaViewBinder extends ItemViewBinder<MerchantEntity.AreaBean, SingleAreaViewBinder.ViewHolder> {
    private String[] colors = {"#000000","#5AA92D","#0086F9","#FF6460","#FC793B"};
    private int i = 0;
    private OnAreaClickListener onAreaClickListener;

    public void setOnAreaClickListener(OnAreaClickListener onAreaClickListener) {
        this.onAreaClickListener = onAreaClickListener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View itemView = inflater.inflate(R.layout.item_area_single, parent, false);
        return new ViewHolder(itemView);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull final MerchantEntity.AreaBean item) {
        holder.txt_area.setText(item.getName());
//        holder.txt_area.setBackgroundColor(Color.parseColor(colors[i]));
//        holder.rl_bg.setBackgroundColor(Color.parseColor(colors[i]));
        i += 1;
        holder.rl_bg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onAreaClickListener != null) {
                    onAreaClickListener.onAreaClick(item);
                }
            }
        });
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView txt_area;
        private View rl_bg;


        ViewHolder(View itemView) {
            super(itemView);

            txt_area = itemView.findViewById(R.id.txt_area);
            rl_bg = itemView.findViewById(R.id.rl_bg);
        }
    }

    public interface OnAreaClickListener {
        void onAreaClick(MerchantEntity.AreaBean item);
    }

}
